﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model;
using HengTong.Model.Db.Hr;


namespace HengTong.ViewModel.Person.SysPersonFamilyVms
{
    public partial class SysPersonFamilyListVm : BasePagedListVM<SysPersonFamilyView, SysPersonFamilySearcher>
    {

        protected override IEnumerable<IGridColumn<SysPersonFamilyView>> InitGridHeader()
        {
            return new List<GridColumn<SysPersonFamilyView>>{
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.MemberName),
                this.MakeGridHeader(x => x.Ethnicity),
                this.MakeGridHeader(x => x.BirthDate),
                this.MakeGridHeader(x => x.WorkOrSchool),
                this.MakeGridHeader(x => x.JobOrGrade),
                this.MakeGridHeader(x => x.ContactPhone),
                this.MakeGridHeader(x => x.RelationshipType),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPersonFamilyView> GetSearchQuery()
        {
            var query = DC.Set<SysPersonFamily>()
                .CheckEqual(Searcher.PersonId, x=>x.PersonId)
                .CheckContain(Searcher.MemberName, x=>x.MemberName)
                .CheckContain(Searcher.WorkOrSchool, x=>x.WorkOrSchool)
                .Select(x => new SysPersonFamilyView
                {
				    ID = x.ID,
                    PersonName = x.Person.Name,
                    MemberName = x.MemberName,
                    Ethnicity = x.Ethnicity,
                    BirthDate = x.BirthDate,
                    WorkOrSchool = x.WorkOrSchool,
                    JobOrGrade = x.JobOrGrade,
                    ContactPhone = x.ContactPhone,
                    RelationshipType = x.RelationshipType,
                })
                .OrderBy(x => x.BirthDate ?? DateTime.MaxValue);
            return query;
        }

    }

    public class SysPersonFamilyView : SysPersonFamily{
        [Display(Name = "姓名")]
        public String PersonName { get; set; }

    }
}
